package main

import (
	"fmt"
	"regexp"
)

/*
golang 正则的使用
*/

func main() {
	// 正则匹配
	flysnowRegexp := regexp.MustCompile(`^http://blog.jiguba.cn/([\d]{4})/([\d]{2})/([\d]{2})/([w-]+).html$`)
	params := flysnowRegexp.FindStringSubmatch("http://blog.jiguba.c/2018/01/20/golang-goquery-examples-selector.html")
	fmt.Println(params)
	for _, param := range params {
		fmt.Println(param)
	}

	var validID = regexp.MustCompile(`^[a-z]+\[[0-9]+\]$`)

	fmt.Println(validID.MatchString("adam[23]"))
	fmt.Println(validID.MatchString("eve[7]"))
	fmt.Println(validID.MatchString("Job[48]"))
	fmt.Println(validID.MatchString("snakey"))

	var validId1 = regexp.MustCompile(`(Kate)`)
	fmt.Println(validId1.MatchString("Kate"))

	var validId2 = regexp.MustCompile(`(Kate1)`)
	fmt.Println(validId2.ReplaceAllString("2313Kate", "hhhhh"))
	fmt.Println(validId2.ReplaceAllString("2313Kate", ""))
	validId3, err := regexp.Compile(`(Kate2)`)
	if err == nil {
		fmt.Println(validId3.ReplaceAllString("2313Kate2", "hhhhh"))
		fmt.Println(validId3.ReplaceAllString("2313Kate2", ""))
	}

	//TestMap := map[int]int{}
	//for i :=1; i<10; i++ {
	//	TestMap[i]= i +1
	//}
	//for k, v := range TestMap{
	//	fmt.Println(k, v)
	//}

}
